package com.zxl.live.tools.alert;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;

/**
 * 功能：
 * 作者： caijun
 * 时间： 2017/3/1  16 : 02
 */
public class MeizuGotoAlertSet implements AlertPermissionUtils.GotoAlertManager {

    @Override
    public void gotoAlert(Context context) {
        int version = getVersion(context);
        Intent intent = new Intent();

        if (version >= 33 && version < 40) {

            intent.setClassName("com.android.settings", "com.android.settings.Settings$AppControlSettingsActivity");

//            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        } else if (version >= 40) {

            intent.setAction("com.meizu.safe.security.SHOW_APPSEC");

//            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            intent.putExtra("packageName", context.getPackageName());

        }
        try {
            context.startActivity(intent.setFlags(1418002432));
        } catch (Exception e) {

        }

    }

    private int getVersion(Context context) {

        int ver = -1;

        String str = Build.DISPLAY;

        if (TextUtils.isEmpty(str) || !str.toLowerCase().contains("flyme")) {

            return -1;

        }

        try {

            String[] split = str.replaceAll(" ", "").toLowerCase().split("\\.");

            if (split.length < 2) {

                return -1;

            }

            try {

                return (Integer.valueOf(split[0].substring(split[0].length() - 1)).intValue() * 10)

                        + Integer.valueOf(split[1].substring(0, 1)).intValue();

            } catch (Exception e) {

                ver = -1;

                return ver;

            }

        } catch (Exception e2) {

            return ver;

        }

    }
}
